package com.bys.admin.ai.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bys.admin.ai.entity.AiApiKey;
import com.bys.admin.ai.service.IAiApiKeyService;
import com.bys.response.R;
import com.bys.vo.PageVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * AI API 秘钥 DO 前端控制器
 * </p>
 *
 * @author bys
 * @since 2025-02-19
 */
@Tag(name = "API 秘钥 接口")
@RestController
@RequestMapping("/ai/api-key")
public class AiApiKeyController {

    @Resource
    private IAiApiKeyService aiApiKeyService;


    @GetMapping("/page")
    @Operation(summary="API密钥分页查询")
    public R<Page<AiApiKey>> page(PageVo pageVo){
        Page<AiApiKey> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        return R.success(aiApiKeyService.page(page));
    }

    @PostMapping("/save")
    @Transactional(rollbackFor = Exception.class)
    public R<Boolean> save(@RequestBody AiApiKey apiKey){
        aiApiKeyService.saveOrUpdate(apiKey);
        return R.success(Boolean.TRUE);
    }

    @DeleteMapping("/remove/{id}")
    @Transactional(rollbackFor = Exception.class)
    public R<Boolean> delete(@PathVariable Long id){
        aiApiKeyService.removeById(id);
        return R.success(Boolean.TRUE);
    }


}
